package student;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class TestStudentTwo {
    public static void main(String[] args) {
        Set<Student> set = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                if (o1.getAge().equals(o2.getAge())) {
                    return o1.getName().compareTo(o2.getName());
                }
                return o1.getAge() - o2.getAge();
            }
        });
//        Set<Student> set = new TreeSet<>((o1, o2) -> o1.getAge() - o2.getAge());
        set.add(new Student("张三1", 22));
        set.add(new Student("张三2", 20));
        set.add(new Student("张三2", 21));
        set.add(new Student("张三4", 22));
        System.out.println(set);

    }
}
